using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeFrame.Core;
using WeFrame.Core.Common;
using WeFrame.Core.Model;
using WeFrame.Test.Model;
using WeFrame.Test.BLL;

namespace WeFrame.Web.Admin.Test
{
    public partial class TestStudentList :  WeFrame.Core.UI.AdminPage
    {

        TestStudentBLL bll = new TestStudentBLL();
        protected List<QueryParam>  queryParamList = new List<QueryParam>();
        protected List<QueryOrder> queryOrderList  = new List<QueryOrder>();
        protected QueryPage queryPage = new QueryPage();

        protected void Page_Load(object sender, EventArgs e)
        {
            ChkAdminLevel("TestStudent", WeFrameEnums.ActionEnum.View.ToString()); //检查权限
            
            if (!Page.IsPostBack)
            {
                PageDataBind();
            }
        }

        /// <summary>
        /// 关健字查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LinkButtonSearch_Click(object sender, EventArgs e)
        {
            queryPage.PageIndex = 1;
            PageDataBind();
        }

        /// <summary>
        /// 设置分页数量
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void TextBoxPageSize_TextChanged(object sender, EventArgs e)
        {
            queryPage.PageSize = int.Parse(TextBoxPageSize.Text);
            PageDataBind();
        }

        /// <summary>
        /// 转到相应页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager_PageChanged(object sender, EventArgs e)
        {
            queryPage.PageIndex = AspNetPager.CurrentPageIndex;
            PageDataBind();
        }

        /// <summary>
        /// 页面数据绑定
        /// </summary>
        protected void PageDataBind() 
        {
            BuildQueryPage();
            BuildQueryParam(TextBoxKeyword.Text.Trim());
            BuildQueryOrder();
            RepeaterDataBind();
            AspNetPagerDataBind();
        }

        /// <summary>
        ///  数据绑定
        /// </summary>
        private void RepeaterDataBind()
        {

            RepeaterList.DataSource = bll.QueryDataSet(queryParamList, queryOrderList, queryPage);
            RepeaterList.DataBind();
        }

        /// <summary>
        /// 分页绑定
        /// </summary>
        private void AspNetPagerDataBind()
        {
            AspNetPager.RecordCount = queryPage.ObjectCount;
            AspNetPager.CurrentPageIndex = queryPage.PageIndex;
            AspNetPager.PageSize = queryPage.PageSize;
            AspNetPager.DataBind();
        }

        /// <summary>
        /// 构建查询条件
        /// </summary>
        /// <param name="keywords"></param>
        protected void BuildQueryParam(string keywords)
        {
            QueryParam name = new QueryParam();
            name.ParamName = "Name";
            name.ParamValue = "%" + keywords + "%";
            name.Operation = " like ";
            queryParamList.Add(name);
        }

        /// <summary>
        /// 构造排序条件
        /// </summary> 
        protected void BuildQueryOrder()
        {
            QueryOrder queryOrder = new QueryOrder();
            queryOrder.OrderName = "Id";
            queryOrder.OrderWay = "Desc";
            queryOrderList.Add(queryOrder);
        }

        /// <summary>
        /// 构造分页
        /// </summary>
        protected void BuildQueryPage()
        {
            queryPage.PageSize = int.Parse(TextBoxPageSize.Text);
        }


        //批量删除
        protected void LinkButtonDelete_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("TestStudent", WeFrameEnums.ActionEnum.Delete.ToString()); //检查权限
            bll.Delete(GetCheckedIds(RepeaterList));
            PageDataBind();
          
        }



    }
}

